package org.zhuxian.cn.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.zhuxian.cn.entity.VO.UserVO;
import org.zhuxian.cn.service.EquipmentBuildsService;
import org.zhuxian.cn.service.UserService;
import org.zhuxian.cn.utils.RedisUtils;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
public class RedisSchedule {
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private UserService userService;
    @Autowired
    private EquipmentBuildsService equipmentBuildsService;

    private static String USER_KEY = "user";


    @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES)
    public void UserToRedis() {
        List<UserVO> allUsers = userService.getAllUsers();
        allUsers.forEach(user -> {
            redisUtils.set(USER_KEY + ":" + user.getId(), user);
        });
    }

    @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES)
    public void RecommendEquipmentBuildsToRedis() {
        equipmentBuildsService.getAllEquipmentBuilds();
    }
}
